{% extends "xadmin/base_site.html" %}
{% load static %}
{# 导入 样式#}
{% block extrastyle %}
    <link rel="stylesheet" href="{% static 'style.css' %}">
{% endblock %}
{% block content-nav %}
{% endblock %}

{% block content %}
    <nav class="navbar navbar-default navbar-static-top">
      <div class="container">
        <!-- Brand and toggle get grouped for better mobile display -->
        <!-- Collect the nav links, forms, and other content for toggling -->
        <div class="collapse navbar-collapse" id="bs-example-navbar-collapse-1">
          <ul class="nav nav-tabs nav-justified">
            <li><a href="{% url 'xadmin:meetingSetting' %}?id={{ meeting_id }}">参与学生 <span class="sr-only">(current)</span></a></li>
            <li><a href="{% url 'xadmin:importStudent' %}?id={{ meeting_id }}">不符合资格学生</a></li>
    {#          //href="{% url 'xadmin:importStudent' %}?id={{ meeting_id }}"#}
            <li><a href="{% url 'xadmin:importStudentGrade' %}?meeting_id={{ meeting_id }}">导入学生成绩</a></li>


            <li><a href="{% url 'xadmin:juryList' %}?meeting_id={{ meeting_id }}">评委列表</a></li>
            <li class="active"><a href="javascript:;">分配评委</a></li>
{#            <li><a href="javascript:;">会议统计</a></li>#}
          </ul>

        </div><!-- /.navbar-collapse -->
      </div><!-- /.container-fluid -->
    </nav>
    <div class="top" style="margin-top: 40px;">
        <div style="float: left; text-align: center; margin-bottom: 30px; margin-top: 8px;">
            <a href="javascript:;">
                <input type="buttom" id="submit-jury" {% if meeting_status == "已结束" %} style="display: none" {% endif %}readonly value="提交" class="btn btn-primary btn_setting">
            </a>
        </div>
        <div style="display: inline-block; margin-top: 1px;">
            <form class="navbar-form navbar-left" method="post">
                    {% csrf_token %}
                <div class="input-group search-group" >
                    {% if q %}<span class="input-group-btn"><a class="btn btn-default" href="?meeting_id={{ meeting_id }}">x</a></span>{% endif %}
                     <input  type="text" name="meeting_id" value="{{ meeting_id }}" hidden>
                     <input id="searchbar" class="form-control" type="text" name="_q_" value="" placeholder="搜索 姓名或学号">
                    <span class="input-group-btn"><button class="btn btn-primary" type="submit"><i class="fa fa-search"></i></button></span>
                </div>
            </form>
        </div>
        <div class="count" style="margin-top: 20px;">
            <span> 共有学生: <span style="color: #1b9dec; margin-right: 20px;">{{ applicationform_list_jury | length }} 人</span>  </span>
        </div>
    </div>
    <div class="content " >
        <table class="table table-hover table-bordered">
        <thead>
            <tr>
{#              <th><input type="checkbox" class="first-checkbox"></th>#}
              <th width="10%">学生姓名</th>
              <th width="15%">学生学号</th>
              <th width="15%">导师</th>
              <th width="10%">入学年份</th>
              <th width="30%">评委老师</th>
            </tr>
        </thead>
        <tbody>
        {% for applicationform_jury in applicationform_list_jury %}
            <tr >
{#                <td><input type="checkbox"></td>#}
                <td>{{ applicationform_jury.0.sname }}</td>
                <td>{{ applicationform_jury.0.sno }}</td>
                <td>{{ applicationform_jury.0.student.tutor }}</td>
                <td>{{ applicationform_jury.0.student.startDate | date:"Y/m" }}</td>
                <td>
                    {% for jury in jury_list %}
                            <label>
                                 <input type="radio" {% if meeting_status == "已结束" %} disabled {% endif %}name="{{ applicationform_jury.0.id }}" id="optionsRadios1" value="{{ applicationform_jury.0.id }}:{{ jury.id }}" {% if applicationform_jury.1.jno == jury.jno %} checked {% endif %}>
                                    {{ jury }}
                            </label>
                    {% empty %}
                        暂无内容
                    {% endfor %}
                </td>
            </tr>
        {% empty %}
            <tr>
                <td>暂无内容</td>
                <td>暂无内容</td>
                <td>暂无内容</td>
                <td>暂无内容</td>
                <td>暂无内容</td>
            </tr>
        {% endfor %}
        </tbody>
        </table>
    </div>
<script>
    // 提交
    $("#submit-jury").click(function () {
        // 获取所有
        var count = $("input:radio:checked").length
        if(count < {{ applicationform_list_jury | length }}){
            alert("请全部分配")
        }else{
            // 格式["申请表id:评委id", ]
            var applicationform_list_jury = []
            $("input:radio:checked").each(function () {
                applicationform_list_jury.push($(this).val())
            })
            var randint = "";
            for(var i = 0; i < 4; i++){
                randint += Math.floor(Math.random()*10);
            }
            var con=prompt("你一共选择了 "+count+" 人,"+"请输入随机验证码提交:" + randint );
            if(con == randint){
                // ajax 提交
                $.ajax({
                    url: "{% url 'xadminData:allotJurySave' %}",
                    type: 'post',
                    data: {"applicationform_list_jury": JSON.stringify(applicationform_list_jury), csrfmiddlewaretoken: '{{ csrf_token }}'},
                    cache: false,
                    success: function (data) {
                        alert(data.status);
                    },
                    error: function (xhr) {
                        alert("出现错误");
                    }
                })
            }else {
                alert("验证码错误")
            }


        }
    });
</script>
{% endblock %}